home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cfengine-1.5.3 / src / proto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-16  |  3.5 KB  |  115 lines

  1. /* 
  2.  
  3.         Copyright (C) 1995
  4.         Free Software Foundation, Inc.
  5.  
  6.    This file is part of GNU cfengine - written and maintained 
  7.    by Mark Burgess, Dept of Computing and Engineering, Oslo College,
  8.    Dept. of Theoretical physics, University of Oslo
  9.  
  10.    This program is free software; you can redistribute it and/or modify it
  11.    under the terms of the GNU General Public License as published by the
  12.    Free Software Foundation; either version 2, or (at your option) any
  13.    later version.
  14.  
  15.    This program is distributed in the hope that it will be useful,
  16.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.   You should have received a copy of the GNU General Public License
  21.   along with this program; if not, write to the Free Software
  22.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  23.  
  24. */
  25.  
  26. /*******************************************************************/
  27. /*                                                                 */
  28. /* File Image copying                                              */
  29. /*                                                                 */
  30. /* client part for remote copying                                  */
  31. /*                                                                 */
  32. /*******************************************************************/
  33.  
  34. #define INET 1
  35.  
  36. #include "cf.defs.h"
  37. #include "cf.extern.h"
  38.  
  39. /*********************************************************************/
  40.  
  41. IdentifyForVerification(sd,fqname)
  42.  
  43. int sd;
  44. char *fqname;
  45.  
  46. { char sendbuff[bufsize],dnsname[maxvarsize];
  47.   struct sockaddr_in saddr;
  48.   struct in_addr *iaddr;           
  49.   struct hostent *hp;
  50.   struct stat statbuf;
  51.   int n, len;
  52.  
  53. bzero(sendbuff,bufsize);
  54.  
  55. if (strcmp(VDOMAIN,CF_START_DOMAIN) == 0)
  56.    {
  57.    CfLog(cferror,"Undefined domain name","");
  58.    return false;
  59.    }
  60.  
  61. /* First we need to find out the IP address and DNS name of the socket
  62.    we are sending from. This is not necessarily the same as fqname if
  63.    the machine has a different uname from its IP name (!) This can
  64.    happen on stupidly set up machines or on hosts with multiple
  65.    interfaces, with different names on each interface ... */ 
  66.  
  67. len = sizeof(struct sockaddr_in);
  68.  
  69. if (getsockname(sd,(struct sockaddr *)&saddr,&len) == -1)
  70.    {
  71.    CfLog(cferror,"Couldn't get socket address\n","getsockname");
  72.    return false;
  73.    }
  74.  
  75. Debug("Identifying as %s i.e. %s, with signature %d\n",inet_ntoa(saddr.sin_addr),VFQNAME,CFSIGNATURE);
  76.  
  77. iaddr = &(saddr.sin_addr);
  78. hp = gethostbyaddr((void *)iaddr,sizeof(struct in_addr),AF_INET);
  79.  
  80. if ((hp == NULL) || (hp->h_name == NULL))
  81.    {
  82.    CfLog(cferror,"Couldn't lookup IP address\n","gethostbyaddr");
  83.    return false;
  84.    }
  85.  
  86. strcpy(dnsname,hp->h_name);
  87.  
  88. /*if (strstr(hp->h_name,VDOMAIN)== 0)*/
  89.  
  90. if (strstr(hp->h_name,".") == 0) 
  91.    {
  92.    strcat(dnsname,".");
  93.    strcat(dnsname,VDOMAIN);
  94.    }
  95.  
  96. #ifdef NT
  97. if (stat("/etc/passwd",&statbuf) == -1)
  98.    {
  99.    CfLog(cferror,"Make sure you have made /etc/passwd with mkpasswd for remote copy to work\n");
  100.    }
  101. #endif 
  102.  
  103. sprintf(sendbuff,"CAUTH %s %s %s %d",inet_ntoa(saddr.sin_addr),dnsname,getpwuid(getuid())->pw_name,CFSIGNATURE);
  104.  
  105. if ((n = send(sd,sendbuff,bufsize,0)) == -1)
  106.    {
  107.    printf("send\n");
  108.    sprintf(OUTPUT,"socket verify only sent %d bytes\n",n);
  109.    CfLog(cferror,OUTPUT,"send");
  110.    return false;
  111.    }
  112.  
  113. return true;
  114. }
  115.